package com.example.websocket.controller;

import com.example.websocket.meassge.HelloMessage;
import com.example.websocket.response.Greeting;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

/**
 * GreetingController
 */
@Controller
public class GreetingController {
    @MessageMapping("/hello")  //消息映射路径
    @SendTo("/topic/greetings")     //发送的路径
    public Greeting greeting(HelloMessage message /*传入的消息内容*/) throws Exception {
        Thread.sleep(1000); // simulated delay
        return new Greeting("Hello, " + message.getName() + "!");
    }
}
